package com.itxx.keyCase.Test2;
//
public class MyThread implements Runnable {
    private  int ticket = 200;


    @Override
    public void run() {
       while(true){
           boolean mothed = mothed();
           if(mothed){
               break;
           }
       }
    }

    private  synchronized boolean mothed() {
        if (ticket <= 0) {
            System.out.println(Thread.currentThread().getName() + ":票买完了");
            return true;
        } else  {
            try {
                Thread.sleep(10);

            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "买:" + ticket + "张票");
            ticket--;
        }
        return false;
    }
}